/*This file is part of WZLibCP.

 *  WZLibCP is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

 *  WZLibCP is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

 *  You should have received a copy of the GNU General Public License
    along with WZLibCP.  If not, see <http://www.gnu.org/licenses/>.
		
	Author: calc0000
*/
#ifndef __WZLIB_WZOBJECT_H
#define __WZLIB_WZOBJECT_H
#include "WZLibConfig.h"

#include <string>

#include "WZBinaryReader.h"

namespace WZLib{
	/**\brief Abstract base class for almost everything in WZLibCP.

	WZObject is the base class for WZFile, WZDirectory, WZImage, and WZImageProperty.
	It is abstract, and so cannot be instantiated.  It contains common needed members
	for objects in this library, such as a name, size, and checksum.  Not all of these
	are used in every subclass, however.  Refer to individual subclass documentation 
	for implementation details.
	*/
	class WZObject{
	public:
		//!Enumeration to determine the type of this object.
		typedef enum _enum_ObjectType{
			Unknown,
			File,
			ListFile,
			Directory,
			Image,
			Property,
		}ObjectType;
	protected:
		//!The name of this object.  The details vary by subclass.  Access with name().
		std::string			_name;
		//!The type of this object.  See ObjectType.
		ObjectType			_type;
		//!The size of this object.  The details vary by subclass.  Access with size().
		int					_size;
		//!The checksum of this object.  The details vary by subclass.  Access with checksum().
		int					_checksum;
		//!The offset of this object.  The details vary by subclass.  Access with offset().
		int					_offset;
		//!The parent object of this object.  Access with (*(parent())) (See parent()).
		WZObject*			_parent;
		//!Whether or not this object has been parsed.  See parse().
		bool				_parsed;
	public:
		//Constructor
		/**\brief Constructor that takes a name and object type.

		\param name The name of this object.
		\param type The type of this object (See ObjectType).
		*/
		ctor				WZObject(std::string name="",ObjectType type=Unknown);
		//Destructor
		/**\brief Object destructor.

		Is a no-op in WZObject.
		*/
		dtor				~WZObject();
		//Getters/Setters
		//!Get the name of this object.
		std::string&		name();
		//!Get the type of this object.
		ObjectType&			type();
		//!Get a pointer to the object parent of this object.
		WZObject**			parent();
		//!Get whether or not this object has been parsed.
		bool				parsed();
		//Methods
		/**\brief Virtual abstract parsing method.

		This parse method must be overloaded in a subclass in order
		for the subclass to not be abstract.  Some subclasses, such
		as WZExtendedProperty, require more information to parse,
		so calling this version of the function will return, in
		WZExtendedProperty 's case, a Error_WZLib_WZExtendedProperty_Parse_WrongParseFunction.
		See individual subclass documentation for implementation
		details.

		In addition, some subclasses may not require a WZBinaryReader
		to be supplied to parse, (see WZPNGProperty).  In these cases,
		reader will be NULL by default.  Again, see individual subclass
		documentation for more information.

		\param reader The WZBinaryReader to use to parse this object.  Not always required.
		*/
		virtual ErrorCode	parse	(WZBinaryReader* reader)=0;
		/**\brief Static method to return the string representation of the given object type.

		For example, if given File, this will return "WZFile".

		\param type Object type to representize.
		*/
		static std::string	typeName(ObjectType type);
	};
};

#endif